using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace MCGameEngine.Sprite_Layer
{
    class SpriteLayer : Microsoft.Xna.Framework.GameComponent
    {
        private int index = 0;

        private Dictionary<string, Sprite> sprites;

        public SpriteLayer(MyGame game): base(game)
        {
            sprites = new Dictionary<string, Sprite>();
        }

        public void Add(Sprite sp)
        {
            sprites.Add("unnamed" + index, sp);
            index++;
        }

        public void Add(Sprite sp, string name)
        {
            sprites.Add(name, sp);
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            foreach (Sprite s in sprites.Values)
            {
                s.Update(elapsed);
            }

            base.Update(gameTime);
        }

        public void Draw()
        {
            foreach (Sprite s in sprites.Values)
            {
                ((MyGame)this.Game).spriteBatch.Draw(s.Frames, s.Position, s.CurrentFrame, s.Filter);
            }
        }
    }
}